package com.taotao.web.controller;

import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.WebResource;
import com.taotao.vo.PicVo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.commons.CommonsMultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * author: 王明跃
 * Create at: 18/7/7下午2:09
 */
@Controller
@RequestMapping("/pic")
public class UpLoadController {


    @ResponseBody
    @RequestMapping("/upload")
    public PicVo upload(@RequestParam("uploadFile") CommonsMultipartFile commonsMultipartFile) throws IOException {
        Client client = Client.create();
        String name = commonsMultipartFile.getOriginalFilename();
        String path = "http://172.16.26.1:8080/img/" + name;
//        String realPath = "/img/" + name;
        WebResource resource = client.resource(path);
        resource.put(commonsMultipartFile.getInputStream());
        PicVo picVo = new PicVo();
        picVo.setError(0).setUrl(path);
        return picVo;
    }
}
